<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>- 表单验证 jQuery Validation</title>
<meta name="keywords" content="">
<meta name="description" content="">

<link rel="shortcut icon" href="favicon.ico">
<link href="/hadmin/css/bootstrap.min.css" rel="stylesheet">
<link href="/hadmin/css/font-awesome.css" rel="stylesheet">
<link href="/hadmin/css/animate.css" rel="stylesheet">
<link href="/hadmin/css/style.css" rel="stylesheet">

</head>

<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>jQuery Validate 简介</h5>
					</div>
					<div class="ibox-content">
						<p th:text="'为【'+${user.nickName}+'】分配角色'"></p>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>选择角色</h5>
					</div>
					<div class="ibox-content">
						<form class="form-horizontal" id="frm" method="post" action="/admin/user/save">
							<input type="hidden" id="id" name="id" value="${user.id}">
							<div class="form-group" th:each="role:${roles}">
								<div class="col-sm-12">
									<div class="checkbox i-checks">
										<label> <input type="checkbox" th:value="${role.id}" name="roleIds" checked="checked">
										</label>
									</div>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-8 col-sm-offset-3">
									<button class="btn btn-primary" type="submit">提交</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>

	</div>
	<!-- 全局js -->
	<div th:include="/admin/common/common"></div>
	<script type="text/javascript">
    $(document).ready(function () {
	    $("#frm").validate({
    	    rules: {},
    	    messages: {},
    	    submitHandler:function(form){
    	    	$.ajax({
   	    		   type: "POST",
   	    		   dataType: "json",
   	    		   url: "/admin/user/grant/" + ${user.id},
   	    		   data: $(form).serialize(),
   	    		   success: function(msg){
	   	    			layer.msg(msg.message, {time: 2000},function(){
	   						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	   						parent.layer.close(index);
	   					});
   	    		   }
   	    		});
            }
    	});
    });
    </script>

</body>

</html>
